package com.sharing.controller;

import com.sharing.common.Page;
import com.sharing.common.Result;
import com.sharing.domain.Hobby;
import com.sharing.domain.User;
import com.sharing.domain.UserHobby;
import com.sharing.mapper.HobbyMapper;
import com.sharing.service.HobbyService;
import com.sharing.service.UserHobbyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author MingTian
 * @version 1.0
 * @description TODO
 * @date 2023/4/3 10:29
 */
@RestController
@RequestMapping("/hobby")
public class HobbyController {
    @Autowired
    private HobbyService hobbyService;

    /**
     * 查询一级兴趣
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/first")
    public Result<Page<Hobby>> selectFirstLevelHobby(Integer page, Integer size) {
        return hobbyService.selectFirstLevelHobby(page, size);
    }

    /**
     * 根据一级兴趣id查询对应的二级兴趣
     * @param parentId
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/second")
    public Result<Page<Hobby>> selectSecondLevelHobbyByParentId(Integer parentId, Integer page, Integer size) {
        return hobbyService.selectSecondLevelHobbyByParentId(parentId, page, size);
    }

    /**
     * 新增一级兴趣
     * @param hobby
     * @return
     */
    @PostMapping("/first")
    public Result<Hobby> insertFirstLevelHobby(@RequestBody Hobby hobby) {
        return hobbyService.insertFirstLevelHobby(hobby);
    }

    /**
     * 新增二级兴趣
     * @param hobby
     * @return
     */
    @PostMapping("/second")
    public Result<Hobby> insertSecondLevelHobby(@RequestBody Hobby hobby) {
        return hobbyService.insertSecondLevelHobby(hobby);
    }

    /**
     * 删除一级兴趣
     * @param ids
     * @return
     */
    @DeleteMapping("/first")
    public Result<Integer> deleteFirstLevelHobby(@RequestParam List<Integer> ids) {
        return hobbyService.deleteFirstLevelHobby(ids);
    }

    /**
     * 删除二级兴趣
     * @param ids
     * @return
     */
    @DeleteMapping("/second")
    public Result<Integer> deleteSecondLevelHobby(@RequestParam List<Integer> ids) {
        return hobbyService.deleteSecondLevelHobby(ids);
    }
}
